<!-- 企业信息审核 -->
<template>
  <div class="home-page-content">
    <h3 class="mb-20">经营信息接收</h3>
    <Form ref="formData" :model="formData" :label-width="80">
      <Row :gutter="30">
        <Col span="6">
          <FormItem label="项目名称" prop="projectName">
            <Input v-model="formData.projectName" placeholder="请输入"></Input>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="信息类型" prop="infoType">
            <Select v-model="formData.infoType" placeholder="全部" clearable>
              <Option :value="value" v-for="(label, value) in EnumBusinessTypeStatus" :key="value">{{ label }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="6">
          <FormItem label="产业标记" prop="industryMarkName">
            <Select v-model="formData.industryMarkName" placeholder="全部" clearable>
              <Option :value="it.name" v-for="(it, index) in industryAssignsList" :key="index">{{ it.name }}</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="6" class="com-action-search-btn">
          <Button type="primary" icon="md-search" @click="handleSubmit('formData')">查询</Button>
          <BtnPlain type="primary" @click="handleReset('formData')">
            <Icon type="md-refresh" />
            <span>重置</span>
          </BtnPlain>
        </Col>
      </Row>
    </Form>
    <Table :columns="columns" :data="listData">
      <template slot-scope="{ row }" slot="receiveStatus">
        <BtnPlain :type="row.receiveStatus | getAcceptStatus">{{ row.receiveStatusName }}</BtnPlain>
      </template>
      <template slot-scope="{ row }" slot="action">
        <BtnText v-if="row.receiveStatus === 'UnReceive'" type="green" @BtnClick="onView(row)">接收</BtnText>
        <BtnText v-if="row.receiveStatus === 'UnReceive'" type="error" @BtnClick="onRefuse(row)">拒收</BtnText>
        <BtnText v-if="row.receiveStatus !== 'UnReceive'" type="primary" @BtnClick="onView(row)">详情</BtnText>
      </template>
    </Table>
    <PageAtion
      v-if="formData.total"
      :total="formData.total"
      :size.sync="formData.size"
      :page.sync="formData.page"
      @pageSizeChange="pageSizeChange"
    />

    <Modal v-model="modalRefuse" width="400" title="审核拒绝理由" :mask-closable="false">
      <Input v-model="reasonForRejection" type="textarea" :rows="4" placeholder="请填写拒绝理由" />
      <Row slot="footer" type="flex" justify="center">
        <BtnPlain type="primary" @click="modalRefuse = false">取消</BtnPlain>
        <Button type="primary" @click="onSub">提交</Button>
      </Row>
    </Modal>
  </div>
</template>

<script>
import { busInfoNotificationPageList, busInfoNotificationRejection } from '@/api/businessInformationManage.js'
import { getDictTreeByParentId } from '@/api/system.js'

export default {
  name: 'businessInformationReceive',
  data () {
    return {
      formData: {
        projectName: '',
        infoType: '',
        industryMarkName: '',
        page: 1,
        size: 10,
        total: 10,
      },
      columns: [
        {
          title: '项目名称',
          key: 'projectName',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '信息类型',
          key: 'infoTypeName',
          minWidth: 160,
          tooltip: true
        },
        {
          title: '省份',
          key: 'province',
          minWidth: 120,
        },
        {
          title: '城市',
          key: 'city',
          minWidth: 120,
        },
        {
          title: '产业标记',
          key: 'industryMarkName',
          minWidth: 160,
          tooltip: true
        },

        {
          title: '项目阶段',
          key: 'projectStageName',
          minWidth: 100,
        },
        {
          title: '发布人',
          key: 'publisher',
          minWidth: 120,
        },
        {
          title: '发布时间',
          key: 'publishTime',
          minWidth: 170,
        },
        {
          title: '接受状态',
          slot: 'receiveStatus',
          minWidth: 160,
        },
        {
          title: '操作',
          slot: 'action',
          width: 140,
          align: 'center',
          fixed: 'right'
        },
      ],
      listData: [],
      EnumBusinessTypeStatus: {
        ProfessionRelevance: '产业链关联',
        AllUserBusiness: '全民经营',
        ExternalStatement: '项目备案',
      },
      locationInfo: {},
      industryAssignsList: [],
      modalRefuse: false,
      reasonForRejection: '',
      busInfoNotificationId: '',
    };
  },
  async created () {
    this.init()
    this.industryAssignsList = await getDictTreeByParentId({ parentId: 'COMPANY_SERVICE' })
  },
  methods: {
    async init () {
      const request = {
        ...this.formData
      }
      const { data, page, size, total } = await busInfoNotificationPageList(request)
      this.listData = data
      this.formData = { ...this.formData, ...{ page, size, total } }
    },
    handleReset (name) {
      this.$refs[name].resetFields();
      this.init()
    },
    handleSubmit (name) {
      this.init()
    },
    pageSizeChange () {
      console.log(row, 'pageSizeChange', this.formData);
    },
    // 详情
    onView (row, type) {
      const { busInfoNotificationId } = row
      this.$router.push({ path: '/businessInfoReceiveDetails', query: { busInfoNotificationId, type } })
    },
    onRefuse (row) {
      this.modalRefuse = true
      this.busInfoNotificationId = row.busInfoNotificationId
    },
    async onSub () {
      if (!this.reasonForRejection.trim()) {
        this.$Message.error('拒绝理由必填');
        return
      }
      const request = {
        busInfoNotificationId: this.busInfoNotificationId,
        reasonForRejection: this.reasonForRejection
      }
      await busInfoNotificationRejection(request)
      this.$Message.success('用户审核已拒绝');
      this.modalRefuse = false
      this.init()
    },
  },
};
</script>

<style lang="less">
.mb-20 {
  margin-bottom: 20px;
}
</style>

